package com.ktgj.flight.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.flight.domain.FlightOpenProduct;
import com.ktgj.flight.service.IFlightOpenProductService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 机票产品Controller
 * 
 * @author ruoyi
 * @date 2021-11-10
 */
@ControllerAdvice
@RestController
@RequestMapping("/openProduct")
public class FlightOpenProductController extends BaseController
{
    @Autowired
    private IFlightOpenProductService flightOpenProductService;

    /**
     * 查询机票产品列表
     */
    //@PreAuthorize(hasPermi = "flight:product:list")
    @GetMapping("/list")
    public TableDataInfo list(FlightOpenProduct flightOpenProduct)
    {
        startPage();
        List<FlightOpenProduct> list = flightOpenProductService.selectFlightOpenProductList(flightOpenProduct);
        return getDataTable(list);
    }

    /**
     * 导出机票产品列表
     */
    //@PreAuthorize(hasPermi = "flight:product:export")
    @Log(title = "机票产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlightOpenProduct flightOpenProduct) throws IOException
    {
        List<FlightOpenProduct> list = flightOpenProductService.selectFlightOpenProductList(flightOpenProduct);
        ExcelUtil<FlightOpenProduct> util = new ExcelUtil<FlightOpenProduct>(FlightOpenProduct.class);
        util.exportExcel(response, list, "机票产品数据");
    }

    /**
     * 获取机票产品详细信息
     */
    //@PreAuthorize(hasPermi = "flight:product:query")
    @GetMapping(value = "/{state}")
    public AjaxResult getInfo(@PathVariable("state") Long state)
    {
        return AjaxResult.success(flightOpenProductService.selectFlightOpenProductById(state));
    }

    /**
     * 新增机票产品
     */
    //@PreAuthorize(hasPermi = "flight:product:add")
    @Log(title = "机票产品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlightOpenProduct flightOpenProduct)
    {
        return toAjax(flightOpenProductService.insertFlightOpenProduct(flightOpenProduct));
    }

    /**
     * 修改机票产品
     */
    //@PreAuthorize(hasPermi = "flight:product:edit")
    @Log(title = "机票产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlightOpenProduct flightOpenProduct)
    {
        return toAjax(flightOpenProductService.updateFlightOpenProduct(flightOpenProduct));
    }

    /**
     * 删除机票产品
     */
    //@PreAuthorize(hasPermi = "flight:product:remove")
    @Log(title = "机票产品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{states}")
    public AjaxResult remove(@PathVariable Long[] states)
    {
        return toAjax(flightOpenProductService.deleteFlightOpenProductByIds(states));
    }
}
